﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NhanAi.DAO;
using NhanAi.Entity;
namespace NhanAi.Public
{
    public partial class Category : PublicBasePage
    {
        Taxonomy taxonomy;
        List<NhanAi.Entity.Taxonomy> taxonomies;
        List<Post> posts;
        public Taxonomy Taxonomy { get { return taxonomy; } }
        public List<NhanAi.Entity.Taxonomy> Taxonomies { get { return taxonomies; } }
        public List<Post> Posts { get { return posts; } }
        protected void Page_Load(object sender, EventArgs e)
        {
            TaxonomyDao daoTax = new TaxonomyDao();
            string cate = Request["name"] == null ? "" : Request["name"];
            if (cate.Trim() != null)
                if (System.Text.RegularExpressions.Regex.IsMatch(cate, "\\d+"))
                {
                    int taxId = Home.Utils.TypeWrapper.GetInt32(cate);
                    taxonomy = daoTax.Read(taxId, CurrentLanguageCode);
                   if(taxonomy!=null) taxonomies = daoTax.ReadAll(taxId);
                }
                else
                {
                    taxonomy = daoTax.Read(cate, CurrentLanguageCode);
                    if(taxonomy!=null)taxonomies = daoTax.ReadAll(taxonomy.Id);
                }

            if (taxonomy != null)
            {              
                PostDao daoPost = new PostDao();
                int total = 0;
                posts = daoPost.ReadByTaxonomy(15, 1, CurrentLanguageCode, "post", taxonomy.Id, null, false, -1, NhanAi.App_Code.NAConstants.POST_STA_POST, null, null, out total);

                int page = Home.Utils.TypeWrapper.GetInt32(Request["page"]);
                paging.PageNumber = page;
                paging.TotalItemCount = total;
            }

            paging.PageSize = 15;

        }
    }
}